/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2017_11_01			*/
/*	File:		CmSspEng.cpp			*/
/********************************************************/

#include "CmSspEng.h"

int main(int argc, char* argv[])
{
	CmNet::CCmTcp CTcp;
	CmCls::CCmTime CTime;
	UCHAR uszRecv[CM_KBYTES8] = {'\0'};
	UCHAR uszSend[CM_KBYTES8] = {'\0'};
	int iRecv = 0, iCount = 0, iTotal = 0;
	char szUrl[CM_URL] = "192.168.21.221:80";

	iTotal = argc > 1 ? atoi(argv[1]) : 1;
	sprintf((char*)uszSend, CM_SSP_HEAD, strlen(CM_SSP_BODY), CM_SSP_BODY);

	CTime.CmTimeOn();

	for (; iCount < iTotal; iCount ++) {
		if (CM_SUCCESS == CTcp.CmTcpConnect(szUrl)) {
			if (CTcp.CmNetSend(uszSend, strlen((char*)uszSend)) > 0) {
				memset(uszRecv, '\0', CM_KBYTES8);
				if ((iRecv = CTcp.CmNetRecv(uszRecv, CM_KBYTES8)) > 0) {
					CM_PRINT("\n{%s}\n", (char*)uszRecv);
				}
				else {
					CM_ERROR("Count[%08d]: Failed to CmNetRecv\n", iCount);
				}
			}
			else {
				CM_ERROR("Count[%08d]: Failed to CmNetSend\n", iCount);
			}
			CTcp.CmNetClose();
		}
		else {
			CM_ERROR("Failed to CmTcpConnect\n");
			break;
		}
	}

	CM_PRINT("Total: %d\n", iCount);

	CTime.CmTimeOff();
	CTime.CmTimeDisplay();

	return CM_SUCCESS;
}
